package com.hue.springbootaop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Author: 姚凤桥
 * @Date: 2022/4/15 11:52
 * @Description:
 */
@Aspect
@Component
public class MethodReportAspect {
    /**
     * 环绕通知，检查方法注解，实现方法上报功能
     *
     * @param joinPoint
     */
    @Around("@annotation(com.hue.springbootaop.annotation.MethodReport)")
    public Object methodReport(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();

        //执行目标方法,获取返回结果
        Object proceed = joinPoint.proceed(joinPoint.getArgs());

        long endTime = System.currentTimeMillis();
        System.out.println("方法执行时间:" + (endTime - startTime) + "ms");

        return proceed;
    }
}
